package sz.szsmk.citizencard.ui.fragment;

import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.RequiresApi;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.util.LogUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.MainFragmentBinding;
import sz.szsmk.citizencard.dialog.TwoButtonDialog;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CloudFlashRes;
import sz.szsmk.citizencard.model.network.bean.response.GetOrderOpenidRes;
import sz.szsmk.citizencard.model.network.bean.response.HomeHeadFuncResponse;
import sz.szsmk.citizencard.model.network.bean.response.HomeWeathRes;
import sz.szsmk.citizencard.model.network.bean.response.IUserInfo;
import sz.szsmk.citizencard.model.network.bean.response.NoticeMainres;
import sz.szsmk.citizencard.model.network.bean.response.OneWordRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryAllFunctionNewRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryInterductionAreaRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryMainPageFunctionRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryPageResourceRes;
import sz.szsmk.citizencard.model.network.bean.response.SeleciUserAuthRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfoResponse;
import sz.szsmk.citizencard.model.network.dzbean.res.MessageEvent;
import sz.szsmk.citizencard.mvp.contract.IAPPMainContact;
import sz.szsmk.citizencard.mvp.presenter.APPHomePresenter;
import sz.szsmk.citizencard.ui.activity.OnCustomBottomCallback;
import sz.szsmk.citizencard.ui.activity.OnCustomTopCallback;
import sz.szsmk.citizencard.ui.adapter.AppHomeBannerAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeBannerAdapter1;
import sz.szsmk.citizencard.ui.adapter.AppHomeCardAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeCultureAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeFinanceAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeGridAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeHeadAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeModule1Adapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeModule2Adapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeMyGridAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeRecommandAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeSaleAdapter;
import sz.szsmk.citizencard.ui.adapter.AppHomeThemeAdapter;
import sz.szsmk.citizencard.ui.adapter.bean.AppHomeCardBean;
import sz.szsmk.citizencard.ui.base.IBaseFragment;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.ButtonUtils;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.Density;
import sz.szsmk.citizencard.util.JumpThirdView;
import sz.szsmk.citizencard.util.JumpUtils;
import sz.szsmk.citizencard.util.SharedPreferencesTool;
import sz.szsmk.citizencard.util.StringUtils;
import zhy.com.highlight.HighLight;
import zhy.com.highlight.interfaces.HighLightInterface;
import zhy.com.highlight.position.OnBottomPosCallback;
import zhy.com.highlight.shape.BaseLightShape;
import zhy.com.highlight.shape.CircleLightShape;
import zhy.com.highlight.shape.RectLightShape;
import zhy.com.highlight.view.HightLightView;

import static com.bumptech.glide.load.engine.DiskCacheStrategy.SOURCE;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/18 15:12
 * description: APP首页
 */
public class MainFragment extends IBaseFragment<APPHomePresenter, MainFragmentBinding>
        implements IAPPMainContact.IAPPMainView {

    private HighLight mHightLight;
    private DelegateAdapter delegateAdapter;
    AppHomeCardAdapter cardAdapter;
    private LinkedList<DelegateAdapter.Adapter> adapters;
    AppHomeCardBean appHomeCardBean;
    private AppHomeGridAdapter gridAdapter;
    private AppHomeMyGridAdapter myGridAdapter;
    AppHomeFinanceAdapter financeAdapter;
    AppHomeCultureAdapter cultureAdapter;
    AppHomeSaleAdapter saleAdapter;
    private AppHomeThemeAdapter themeAdapter;
    AppHomeRecommandAdapter appHomeRecommandAdapter;
    private AppHomeModule1Adapter module1Adapter;
    private AppHomeModule2Adapter module2Adapter;
    private List<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> function_list = new ArrayList<>();
    private List<HomeHeadFuncResponse.FunctionListBean> headFuncList=new ArrayList<>();
    private List<QueryMainPageFunctionRes.MainPageClassListBean> classList = new ArrayList<>();
    private AppHomeBannerAdapter bannerAdapter0;
    private AppHomeBannerAdapter1 bannerAdapter1;
    private AppHomeHeadAdapter headAdapter;
    private SwipeRefreshLayout swipeRefreshLayout;
    private HomeWeathRes homeWeathRes;
    private String access_token;
    private LinearLayout goverId;
    private LinearLayout cardId;

    private int scrollBottom = 0;
    //    AppHomeBannerAdapter bannerAdapter;

    public static MainFragment getInstance() {
        MainFragment mainFragment = new MainFragment();
        return mainFragment;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.main_fragment;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void initViews() {
        EventBus.getDefault().register(this);

//        goverId = (LinearLayout) getActivity().findViewById(R.id.tab_dzsmk);//市民卡
//        cardId = (LinearLayout) getActivity().findViewById(R.id.tab_sc);//政务

//        showNextTipViewOnCreated();

        appHomeCardBean = new AppHomeCardBean();   //首页的市民卡信息
        initLayout();
        DaggerApplication.setAppHomePresenter(mPresenter);
        DaggerApplication.setHomeryheight(0);
//        appHomePresenter = mPresenter;
        swipeRefreshLayout = dataBinding.swipeRefreshLayout;
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.firstSearchUserLevel();
                mPresenter.queryTheme(43);
                mPresenter.selectUserAuth("");
                mPresenter.queryGoverList(44);
                mPresenter.queryMainPageFunction();
                mPresenter.getBanner();
                mPresenter.getAd(42);
                mPresenter.queryText();
                mPresenter.queryOneWordAd();
                mPresenter.queryAreaInfo();
                mPresenter.getMainNotice();
            }
        });

        mPresenter.firstSearchUserLevel();
        mPresenter.queryTheme(43);
        mPresenter.selectUserAuth("");
        mPresenter.queryGoverList(44);
        mPresenter.queryMainPageFunction();
        mPresenter.getBanner();
        mPresenter.getAd(42);
        mPresenter.queryText();
        mPresenter.queryOneWordAd();
        mPresenter.queryAreaInfo();
        mPresenter.getMainNotice();
    }

    private RecyclerView mainView;


        VirtualLayoutManager layoutManager; //alibaba VLayout

    private void initLayout() {

         mainView = dataBinding.mainView;
      layoutManager = new VirtualLayoutManager(getActivity()) {

            @Override
            public boolean canScrollVertically() {
                return true;
            }
        };
        mainView.setLayoutManager(layoutManager);
        mainView.setNestedScrollingEnabled(false);
        mainView.setHasFixedSize(true);
        RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
        mainView.setRecycledViewPool(viewPool);
        viewPool.setMaxRecycledViews(0, 30);
        delegateAdapter = new DelegateAdapter(layoutManager, true);
        mainView.setAdapter(delegateAdapter);
        adapters = new LinkedList<>();

        mainView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (homeWeathRes != null) {
                    cardAdapter.invalidateData();
                }
            }
        });

        DefaultLayoutHelper headHelper = new DefaultLayoutHelper();
        headAdapter = new AppHomeHeadAdapter(getActivity(), headHelper);
        headAdapter.setBaseInterface(new AppHomeHeadAdapter.BaseInterface(){
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String id, HomeHeadFuncResponse.FunctionListBean bean) {
                if (ButtonUtils.isFastClick()) {
//                    JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,bean);
                    JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,null);
                }
            }
        });

        adapters.add(headAdapter); //首页的搜索框 天气等元素
//
        bannerAdapter0 = new AppHomeBannerAdapter(getActivity(), headHelper,0);
        bannerAdapter0.setBaseInterface(new AppHomeBannerAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header,QueryPageResourceRes.ResourceListBean resourceListBean) {
                QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
                bean.setModularId(resourceListBean.getModularId());
                JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, "",bean);//H5页面的跳转方法
            }
        });
        adapters.add(bannerAdapter0);


        cardAdapter = new AppHomeCardAdapter(getActivity(), headHelper, dataBinding.rlBack);
        cardAdapter.GhfOnClick(new AppHomeCardAdapter.GhfInterface() {
            @Override
            public void onClick(View view, int position) {
                mPresenter.selectUserAuth("ghf");
            }
        });
//        adapters.add(cardAdapter);//首页的卡信息


        //首页的四个应用
//        myGridAdapter=new AppHomeMyGridAdapter(getActivity(),headHelper);
//        myGridAdapter.setBaseInterface(new AppHomeMyGridAdapter.BaseInterface() {
//            @Override
//            public void onClick(View view, String url, String syslabl, int need_header, String id, HomeHeadFuncResponse.FunctionListBean bean) {
//                if (ButtonUtils.isFastClick()) {
//                    JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,bean);
//                }
//            }
//        });
//
//        adapters.add(myGridAdapter);

        //首页的我的应用
        gridAdapter = new  AppHomeGridAdapter(getActivity(), headHelper);
        gridAdapter.GridMoreOnClick(new AppHomeGridAdapter.GridMoreInterface() {
            @Override
            public void onClick(View view, int position) {
                if (access_token != null) {
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.TO_GOVER));
                } else {
                    JumpUtils.jump(getActivity(), "login", 0);
                }
            }
        });

        gridAdapter.setBaseInterface(new AppHomeGridAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String id, QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean) {
                if (ButtonUtils.isFastClick()) {
                    JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, id,bean);
                }
            }
        });
        adapters.add(gridAdapter);

        bannerAdapter1 = new AppHomeBannerAdapter1(getActivity(), headHelper,1);
        bannerAdapter1.setBaseInterface(new AppHomeBannerAdapter1.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header,QueryPageResourceRes.ResourceListBean resourceListBean) {
                QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
                bean.setModularId(resourceListBean.getModularId());
                JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, "",bean);//H5页面的跳转方法
            }
        });
        adapters.add(bannerAdapter1);


//        themeAdapter = new AppHomeThemeAdapter(getActivity(), headHelper);
//        themeAdapter.setBaseInterface(new AppHomeThemeAdapter.BaseInterface() {
//            @Override
//            public void onClick(View view, String url, String syslabl, int need_header,int modularId) {
//                QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
//                bean.setModularId(modularId);
//                JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, "type",bean);
//            }
//        });
//        adapters.add(themeAdapter);

         appHomeRecommandAdapter =new AppHomeRecommandAdapter(getActivity(),headHelper,1);
        appHomeRecommandAdapter.setBaseInterface(new AppHomeRecommandAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, AdInfo adInfo) {
                JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, "",null);
            }
        });
        adapters.add(appHomeRecommandAdapter);
        financeAdapter = new AppHomeFinanceAdapter(getActivity(), headHelper);
        financeAdapter.setBaseInterface(new AppHomeFinanceAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean) {
                //未处理完的跳转事件
                MessageEvent message = new MessageEvent(MessageEvent.CODE_OPENNG);
                EventBus.getDefault().post(message);
//                JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,null);
//                JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,null);
//                MessageEvent message = new MessageEvent(MessageEvent.CODE_OPENNG);
//                EventBus.getDefault().post(message);
//                Log.d("clark","finance");
            }
        });
        adapters.add(financeAdapter);

        cultureAdapter = new AppHomeCultureAdapter(getActivity(), headHelper);
        cultureAdapter.setBaseInterface(new AppHomeCultureAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean) {
                JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,null);
            }
        });
        adapters.add(cultureAdapter);

        saleAdapter = new AppHomeSaleAdapter(getActivity(), headHelper);
        saleAdapter.setBaseInterface(new AppHomeSaleAdapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean) {
                //未处理完的跳转事件
                JumpThirdView.toNewJumpViewHead(getActivity(), url, syslabl, need_header, mPresenter, id,null);
            }
        });
        adapters.add(saleAdapter);




        module1Adapter = new AppHomeModule1Adapter(getActivity(), headHelper);
        module1Adapter.setBaseInterface(new AppHomeModule1Adapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String modularId) {
                QueryAllFunctionNewRes.ClassListBean.FunctionListBean functionListBean = null ;
                if(!TextUtils.isEmpty(modularId)){
                    functionListBean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
                    functionListBean.setModularId(Integer.valueOf(modularId).intValue());
                }
                JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, "type",functionListBean);

            }
        });
//        adapters.add(module1Adapter);

        module2Adapter = new AppHomeModule2Adapter(getActivity(), headHelper);
        module2Adapter.setBaseInterface(new AppHomeModule2Adapter.BaseInterface() {
            @Override
            public void onClick(View view, String url, String syslabl, int need_header, String modularId) {
                if (ButtonUtils.isFastClick()) {
                    QueryAllFunctionNewRes.ClassListBean.FunctionListBean functionListBean = null ;
                    if(!TextUtils.isEmpty(modularId)){
                        functionListBean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
                        functionListBean.setModularId(Integer.valueOf(modularId).intValue());
                    }
                    JumpThirdView.toNewJumpView(getActivity(), url, syslabl, need_header, mPresenter, "type",functionListBean);
                }
            }
        });

//        adapters.add(module2Adapter);

        delegateAdapter.setAdapters(adapters);
        delegateAdapter.notifyDataSetChanged();

        mPresenter.getIsChecked("android","android");


    }
    private ImageView imginfo;
    private CardView cardinfo;


    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getUserInfo();
        access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        if (StringUtils.isBlank(access_token)) {
            cardAdapter.setLogin(false);
        } else {
            cardAdapter.setLogin(true);
            mPresenter.firstSearchUserLevel();
        }

        mPresenter.queryAllFunctionNew();
        mPresenter.getWeathGeneral();

        mPresenter.getGetOrderId("", "");
        mPresenter.checkSuccessOrderStatus("");
        mPresenter.queryHeadFunc();
        mPresenter.getMainNotice();
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void queryOneWordAdSucc(OneWordRes response) {
        String word = response.getWord();


        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        headAdapter.notifyDataSetChanged();
    }

    @Override
    public void queryOneWordAdFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getUserInfoFail(IUserInfo response) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }

    @Override
    public void getUnlogin(IUserInfo response) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        Constant.isLogin = false;
        cardAdapter.setLogin(false);
//        userHeadAdapter.notifyDataSetChanged();
        final TwoButtonDialog dialog = new TwoButtonDialog(getActivity(), response.getMessage());
        if (response.getCode().equals("000016")) {
            dialog.setOnOkClickListener(new TwoButtonDialog.OnOkClickListener() {
                @Override
                public void onOkClick() {
                    ACache.get(getActivity()).remove("access_token");
                    dialog.cancel();
                }
            });
            dialog.setOnCancelClickListener(new TwoButtonDialog.OnCancelClickListener() {
                @Override
                public void onCancelClick() {
                    ACache.get(getActivity()).remove("access_token");
                    ACache.get(getActivity()).remove("mextend");
                    JumpUtils.jump(mContext, "login", 0);
                    dialog.cancel();
//                    getActivity().finish();
                }
            });
            dialog.show();
        }
    }

    @Override
    public void getUserInfoSucc() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getGetOrderIdFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getGetOrderIdSucc(GetOrderOpenidRes response, String url, String type) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
        Bundle bundle = new Bundle();
        if (type.equals("ghf")) {
            //跳转桂花分
            String murl = Constant.SZ_URL +"?"+ response.getExtend();
            bundle.putString("url", murl);
            bundle.putString(Constant.TITLE, "桂花分");
            JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
        } else if (type.equals("tyhm")) {
//                        String mextends = ACache.get(DaggerApplication.getIns()).getAsString("mextend");
            String murl = url + response.getExtend();
            //苏体通需要自定义ua 传递标识
            bundle.putString("stt", "stt");
            bundle.putString("url", murl);
            JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
        }
    }

    @Override
    public void queryAllFunctionNewFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryAllFunctionNewSucc(QueryAllFunctionNewRes response) {
        Log.d("clark","queryAllFunctionNewSucc");
        function_list.clear();
        function_list = response.getClass_list().get(0).getFunction_list();
        if (function_list.size() != 10) {
            QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean = new QueryAllFunctionNewRes.ClassListBean.FunctionListBean();
            bean.setFunction_name("全部");
            bean.setIcon_url("1");
            function_list.add(bean);
        }
        gridAdapter.setViewData(function_list);
        gridAdapter.notifyDataSetChanged();
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void updataError(BaseBean response) {
        Toast.makeText(mActivity, response.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void queryHeadFuncSuccess(HomeHeadFuncResponse response) {
        Log.e("clark","get headfun success");
        headFuncList.clear();
    //    headFuncList=response.getFunction_list();  //网络获取数据


        HomeHeadFuncResponse.FunctionListBean bean=new  HomeHeadFuncResponse.FunctionListBean();
        bean.setFunction_name(getString(R.string.traveline));
        bean.setLink_url("proto:head:trip");

        HomeHeadFuncResponse.FunctionListBean bean1=new  HomeHeadFuncResponse.FunctionListBean();
        bean1.setFunction_name(getString(R.string.scanQR));
        bean1.setLink_url("proto:head:scan");
        HomeHeadFuncResponse.FunctionListBean bean2=new  HomeHeadFuncResponse.FunctionListBean();
        bean2.setFunction_name(getString(R.string.recharge));
        bean2.setLink_url("proto:head:recharge");
        HomeHeadFuncResponse.FunctionListBean bean3=new  HomeHeadFuncResponse.FunctionListBean();
        bean3.setFunction_name(getString(R.string.wallet));
        bean3.setLink_url("proto:head:wallet");

        headFuncList.add(bean);
        headFuncList.add(bean1);
        headFuncList.add(bean2);
        headFuncList.add(bean3);
        headAdapter.setViewData(headFuncList);
        headAdapter.notifyDataSetChanged();

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }

    @Override
    public void firstSearchUserLevelSucc(AppHomeCardBean response) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        appHomeCardBean = response;
        DaggerApplication.setAppHomeCardBean(appHomeCardBean);
        cardAdapter.setAppHomeCardBean(appHomeCardBean);
    }


    @Override
    public void firstSearchUserLevelFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryThemeSucc(QueryPageResourceRes response) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        themeAdapter.setViewData(response);
        themeAdapter.notifyDataSetChanged();
    }

    @Override
    public void queryThemeFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryGoverListSucc(QueryPageResourceRes response) {
        themeAdapter.setGoverData(response);
        themeAdapter.notifyDataSetChanged();
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryGoverListFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryMainPageFunctionFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getBannerSucc(QueryPageResourceRes response) {
//        bannerAdapter.setBanner(response.getResource_list());
//        bannerAdapter.notifyDataSetChanged();
//        if (swipeRefreshLayout.isRefreshing()) {
//            swipeRefreshLayout.setRefreshing(false);
//        }

    }

    @Override
    public void getBannerFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void queryMainPageFunctionSucc(List<QueryMainPageFunctionRes.MainPageClassListBean> main_page_class_list) {
        classList = main_page_class_list;

        //惠民服务
        QueryMainPageFunctionRes.MainPageClassListBean classListBean = classList.get(0);
        module1Adapter.setViewData(classListBean);
        module1Adapter.notifyDataSetChanged();

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }


        //便民服务
        QueryMainPageFunctionRes.MainPageClassListBean classListBean1 = classList.get(1);
        module2Adapter.setViewData(classListBean1);
        module2Adapter.notifyDataSetChanged();
    }

    @Override
    public void getAdSucc(QueryPageResourceRes response) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getAdFail() {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }

    @Override
    public void getWeathGeneralFail(HomeWeathRes response) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getWeathGeneralSucc(HomeWeathRes response) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        String activePic = response.getActivePicUrlList().get(0);
        String activePicUrl = response.getActivePicUrlList().get(1);
        Glide.with(getContext()).load(activePicUrl).asGif().diskCacheStrategy(SOURCE).into(dataBinding.backView);

        Glide.with(getContext()).load(activePic).into(dataBinding.rightView);
        homeWeathRes = response;
        cardAdapter.setPicData(response);
        cardAdapter.notifyDataSetChanged();

        headAdapter.setWeathData(response);
        headAdapter.notifyDataSetChanged();
    }

    @Override
    public void queryTextSucc(QueryInterductionAreaRes response) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
        Log.d("Clark",response.getInterdution_list().size()+response.getInterdution_list().get(0).getContent());
        bannerAdapter0.setViewData(response.getInterdution_list());
        bannerAdapter0.notifyDataSetChanged();
    }

    @Override
    public void queryTextFail(QueryPageResourceRes response) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void selectUserAuthFail() {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void selectUserAuthSucc(SeleciUserAuthRes response, String type) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
        String access_token = ACache.get(getActivity()).getAsString("access_token");
        List<SeleciUserAuthRes.AuthTypeListBean> authTypeList = response.getAuthTypeList();

        if (type.equals("gjj")) {
            String isAuth = authTypeList.get(1).getIsAuth();
            //0未授权，1已授权，2未实名(L3认证)
            if (isAuth.equals("2")) {
                Bundle bundle = new Bundle();

                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "gjj");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            } else if (isAuth.equals("1")) {
                //跳转公积金
                Bundle bundle = new Bundle();
                String path = Constant.BASE_URL + "app-front-end/#/fund/main?access_token=" + access_token;
                bundle.putString("url", path);
                bundle.putString(Constant.CUST_NAME, appHomeCardBean.getIdCard());
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

            } else if (isAuth.equals("0")) {
                String url = Constant.BASE_URL + "app-front-end/#/fund/main?access_token=" + access_token;

                Bundle bundle = new Bundle();
                bundle.putString("url", url);
                JumpUtils.jumptoNatvie(getActivity(), "webView", 0, bundle);
            }
        }

        if (type.equals("sb")) {
            String isAuth = authTypeList.get(0).getIsAuth();
            //0未授权，1已授权，2未实名(L3认证)
            if (isAuth.equals("2")) {
                Bundle bundle = new Bundle();

                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "sb");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            } else if (isAuth.equals("1")) {
                //跳转社保
                Bundle bundle = new Bundle();
                String path = Constant.BASE_URL + "app-front-end/#/social/main?access_token=" + access_token;
                bundle.putString("url", path);
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

            } else if (isAuth.equals("0")) {
                String url = Constant.BASE_URL + "app-front-end/#/fundAndSociety/authPage?access_token=" + access_token + "&type=1&name=" + appHomeCardBean.getCustName();

                Bundle bundle = new Bundle();
                bundle.putString("url", url);
                JumpUtils.jumptoNatvie(getActivity(), "webView", 0, bundle);
            }

        }

        if (type.equals("ghf")) {
            String isAuth = authTypeList.get(2).getIsAuth();
            //0未授权，1已授权，2未实名(L3认证)
            if (isAuth.equals("2")) {

                Bundle bundle = new Bundle();

                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "ghf");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            } else if (isAuth.equals("1")) {
                mPresenter.getGetOrderId("", "ghf");
                ACache.get(getContext()).put("ghfScore",authTypeList.get(2).getGhfScore());
            } else if (isAuth.equals("0")) {
                ACache.get(getContext()).put("ghfScore","未授权");
                mPresenter.getGetOrderId("", "ghf");
            }
        }

    }

    @Override
    public void checkSuccessOrderStatusSucc(String orderStatus) {
        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }
        Constant.ORDER_STATUS = orderStatus;
    }

    @Override
    public void checkSuccessOrderStatusFail(CloudFlashRes cloudFlashRes) {

        if (swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

    }

    @Override
    public void getIsCheckedSucc(String checkedstate) {
//            if("1".equals(checkedstate)){
//                boolean   isFirstopen = SharedPreferencesTool.getBoolean(getActivity(), "isFirstopen", true);
//                if(isFirstopen){
//                    new Handler().postDelayed(new Runnable() {
//                        @Override
//                        public void run() {
//                            final     View weatherview = layoutManager.findViewByPosition(0);
//
//                            View cardview = layoutManager.findViewByPosition(1);    //2为recyclerView中item位置，
//
//                            LinearLayout gridview =(LinearLayout)layoutManager.findViewByPosition(2);
//
//                            LinearLayout layout = (LinearLayout)cardview;
//                            imginfo = (ImageView)layout.findViewById(R.id.default_bg);
//                            cardinfo = (CardView)layout.findViewById(R.id.cardView);
////                            imginfo.setVisibility(View.VISIBLE);
////                            cardinfo.setVisibility(View.GONE);
//
//                            final    RecyclerView rec = (RecyclerView)gridview.getChildAt(0);
//
//                            rec.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//                                @Override
//                                public void onGlobalLayout() {
//                                    int width = rec.getWidth();
//                                    int height = rec.getHeight();
//                                    if (width > 0 && height > 0) {
//                                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
//                                            rec.getViewTreeObserver().removeOnGlobalLayoutListener(this);
//                                        } else {
//                                            rec.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//                                        }
//                                        showNextTipView(imginfo,rec,weatherview);
//                                    }
//
//
//                                }
//                            });
//
//
////
//
//
//                        }
//                    },300);
//                }
//            }
    }

    @Override
    public void getIsCheckedFail() {

    }
//成功获取首页的模块
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void queryAreaInfoSuccess(AreaInfoResponse areaInfoResponse) {

        headAdapter.setMainBack(areaInfoResponse.getAreaInfoVoList().get(0).getAdInfoVoList().get(0));
        bannerAdapter1.setBanner(areaInfoResponse.getAreaInfoVoList().get(1).getAdInfoVoList());
        appHomeRecommandAdapter.setBanner(areaInfoResponse.getAreaInfoVoList().get(2),areaInfoResponse.getAreaInfoVoList().get(2).getAdInfoVoList());
        financeAdapter.setViewData(areaInfoResponse.getAreaInfoVoList().get(3));
        cultureAdapter.setViewData(areaInfoResponse.getAreaInfoVoList().get(4));
        cultureAdapter.notifyDataSetChanged();
        saleAdapter.setViewData(areaInfoResponse.getAreaInfoVoList().get(5));
    }

    @Override
    public void queryAreaInfoFail() {

    }

    @Override
    public void getMainNoticeSucc(NoticeMainres noticeMainres) {
        Log.d("clark","message num="+noticeMainres.getUnReadTotal());
        headAdapter.setNewsData(noticeMainres.getUnReadTotal());
        headAdapter.notifyDataSetChanged();
    }

    @Override
    public void getMainNoticeError(String message) {

    }


    public void remove(View view)
    {
        mHightLight.remove();
    }


}

